<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .ad {
            width: 200px;
            height: 200px;
            background-color: #f00;
            position: fixed;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            margin: auto;
            display: none;
        }

        .ad>span {
            float: right;
            width: 20px;
            height: 20px;
            background-color: #aaa;
            color: #fff;
            text-align: center;
            line-height: 20px;
        }
    </style>
</head>

<body>

    <div class="ad" id="ad">
        <span id="c">X</span>
        <p><span id="time"></span>s后关闭广告</p>
    </div>

    <script>

        var oAd = getId('ad');
        var oClose = getId('c');
        var oTime = getId('time');

        ff() ;


        function ff() {
            setTimeout(function () {
                oAd.style.display = 'block';
                // 倒计时
                var j = 10;
                // 先赋值
                oTime.innerHTML = j;
                t = setInterval(function () {
                    j--;
                    oTime.innerHTML = j;
                    if (j === 0) {
                        clearInterval(t);
                        oAd.style.display = 'none';
                        ff() ;
                    }
                }, 1000)
            }, 3000)
        }





        function getId(id) {
            return document.getElementById(id);
        }


    </script>

</body>

</html>